package com.ybliang.plat.common.web;

import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BaseController {

	private Logger LOGGER = LoggerFactory.getLogger(BaseController.class);
	protected static Gson gs = new GsonBuilder()
			.setDateFormat("yyyy-MM-dd HH:mm:ss").disableHtmlEscaping().create();
	
	protected <T> JSONObject decorateData(T data, Consumer<JSONObject> action) {
		JSONObject json = (JSONObject) JSONObject.toJSON(data);
		action.accept(json);
		return json;
	}

	protected <T> List<JSONObject> decorateData(List<T> data, Consumer<JSONObject> action) {
		return data.stream().map(n -> decorateData(n, action)).collect(Collectors.toList());
	}
}
